var addressVue = new Vue({
	el:"#app",
	data:{
		startX:0,
		disX:0,
		startX:0,
		address:[],
		page:1,
		isExcute:false,
		isBotton:false,
		isEmpty:false,
	},
	methods:{
		getList:function(){
			var t = this;
			wx.showLoading({title:"加载中..."});
			this.$http.post(baseUrl+"address/list",{
				pageSize:10,
				currentPage:this.page
			}).then(function(e){
				wx.hideLoading();
				var content = e.data;
				if(content.success){
					if(t.page==1 && content.data.length==0 ){
						t.isEmpty = true;
					}else if(t.page ==1 && content.data.length>0){
						content.data.forEach(function(e){
							t.address.push(e);
						})
					}else if(t.page>1 && content.data.length==0){
						t.isBottom = true;
						wx.showToast({
							title: "已经到最底下了",
							icon: "none",
							duration: 1e3,
							mask: !0
						});
					}else{
						content.data.forEach(function(e){
							t.address.push(e);
						})
					}
				}else{
					wx.showToast({
						title: content.description,
						icon: "none",
						duration: 2e3,
						mask: !0
					});
				}
				t.isExcute = false;
			}).catch(function(e){
				console.error(e);
				wx.hideLoading();
				wx.showToast({
					title: "网络错误，请检查网络",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		touchStart: function(ev) {
			ev = ev || event;
			ev.preventDefault();
			if (ev.touches.length == 1) { //tounches类数组，等于1时表示此时有只有一只手指在触摸屏幕
				this.startX = ev.touches[0].clientX; // 记录开始位置
			}
		},
		touchEnd: function(ev, e) {
			ev = ev || event;
			ev.preventDefault();
			if (ev.changedTouches.length == 1) {
				var endX = ev.changedTouches[0].clientX;
				this.disX = endX - this.startX;
				if (this.disX < 0) {
					e.x = "translate(-100px, 0px)";
					ev.currentTarget.parentNode.parentNode.parentNode.style.cssText = "transform:"+e.x;
				} else if(this.disX >0) {
					e.x = "translate(0px, 0px)";
					ev.currentTarget.parentNode.parentNode.parentNode.style.cssText = "transform:"+e.x;
				}else{
					var choose = URLParam.get("choose");
					if(choose){
						localStorage.setItem("address",JSON.stringify(e));
						Jump.back();
					}
				}
			}
			
			
		},
		handleScroll: function() {
			// 防止重复
			if (this.isExcute) {
				return;
			}
			if (this.isBottom) {
				return;
			}
			var flag = srollEvent.isReachBottom();
			if (!flag) {
				return;
			}
			this.isExcute = true;
			this.page++;
			this.show(listType);
		},
		deleteAddress: function(item) {
			wx.showLoading({
				title: "请求中..."
			});
			var favIds = new Array();
			favIds.push(item.favId);
			this.$http.post(baseUrl + "/address/remove", {
				addressGuid: item.addressGuid
			}).then(function(s){
				wx.hideLoading();
				var e = s.data;
				e.success ? (wx.showToast({
					title: "删除成功",
					icon: "none",
					duration: 2e3,
					mask: !1
				}), this.address = [], this.page = 1, this.getList()):wx.showToast({
					title: e.description,
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			}).catch(function(error){
				wx.hideLoading(), console.log(error), wx.showToast({
					title: "网络错误，请检查网络",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
				
			});
		},
		add:function(){
			Jump.to(page.address.add,"type=add");
		},
		edit:function(item){
			Jump.to(page.address.add,"type=edit&name="+item.name+"&tel="+item.tel+"&area="+item.area+"&address="+item.address+"&default="+item.default);
		}
	},
	mounted: function() {
		window.addEventListener("scroll", this.handleScroll, {
			passive: false
		});
	},
	created:function(){
		this.getList();
	}
});